package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.modules.orga.mapper.AppMapper;
import com.dhcc.bpm.modules.orga.mapper.OrgaMapper;
import com.dhcc.bpm.modules.orga.mapper.ProduceApplyMapper;
import com.dhcc.bpm.modules.orga.mapper.TestApplyMapper;
import com.dhcc.bpm.modules.safe.entity.BlackRecommend;
import com.dhcc.bpm.modules.safe.mapper.BlackRecommendMapper;
import com.dhcc.bpm.modules.safe.service.IBlackRecommendService;
import com.dhcc.bpm.modules.safe.vo.BlackRecommendVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName BlackRecommendServiceImpl
 * @Description 黑名单推荐表 服务实现类
 * @Author daina
 * @Date 2020/03/16 10:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_black_recommend")
@AllArgsConstructor
public class BlackRecommendServiceImpl extends ServiceImpl<BlackRecommendMapper, BlackRecommend> implements IBlackRecommendService {

	@Autowired
	private OrgaMapper orgaMapper;
	@Autowired
	private AppMapper appMapper;
	@Autowired
	private ProduceApplyMapper produceApplyMapper;
	@Autowired
	private TestApplyMapper testApplyMapper;
	@Override
	public IPage<BlackRecommendVO> selectBlackRecommendPage(IPage<BlackRecommendVO> page, BlackRecommendVO blackRecommend) {
		return page.setRecords(baseMapper.selectBlackRecommendPage(page, blackRecommend));
	}
	/**
	 * @Description 自定义分页 查询黑名单推荐表
	 * @Author daina
	 * @Date 11:03 2020/3/16
	 * @param page
	 * @param blackRecommend
	 * @return com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.safe.vo.BlackRecommendVO>
	 **/
	@Override
	public IPage<BlackRecommendVO> listBlack(IPage<BlackRecommendVO> page, BlackRecommendVO blackRecommend) {
//		List<BlackRecommendVO> blackLists = baseMapper.listBlack(page, blackRecommend);
//		if(blackLists.size() != 0){
//			for (BlackRecommendVO black:blackLists){
//				String appCode = black.getAppCode();
//				String orgaCard = black.getOrgaCode();
//				App app = appMapper.selectByAppCode(appCode);
//				Orga orga = orgaMapper.selectByOrgaCode(orgaCard);
//
//				black.setAppName(app.getAppName());
//				black.setOrgaName(orga.getOrgaName());
//
//				if(black.getEnv().equals("1")){
//					//生产环境
//					ProduceApplyVO produceApply = new ProduceApplyVO();
//					produceApply.setAppId(app.getId());
//					produceApply.setOrgaId(orga.getId());
//					List<ProduceApplyVO> produceApplyLists = produceApplyMapper.selectProduceApplyPage(page,produceApply);
//					black.setIp(produceApplyLists.get(0).getIp());
//				}else{
//					//沙箱环境
//					TestApplyVO testApplyVO = new TestApplyVO();
//					testApplyVO.setAppId(app.getId());
//					testApplyVO.setOrgaId(orga.getId());
//					List<TestApplyVO> testApplyLists = testApplyMapper.selectTestApplyPage(page,testApplyVO);
//					black.setIp(testApplyLists.get(0).getIp());
//				}
//
//			}
//		}
		List<BlackRecommendVO> blackLists = null;
		if("1".equals(blackRecommend.getEnv())){
			blackLists = baseMapper.listBlackProduce(page, blackRecommend);
		}else{
			blackLists = baseMapper.listBlackTest(page, blackRecommend);
		}
		return page.setRecords(blackLists);
	}
}
